package com.pf.java.File;

import java.io.*;

/**
 * 缓冲流
 *
 * ClassName:IO5
 * Package:com.pf.java.File
 *
 * @author: pf
 * @date: 2021/11/6-15:24
 */
public class IO5 {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        copyFile("C:/Users/10970/Desktop/Java学习笔记/牛客网学习/Git使用.md"
                , "C:/Users/10970/Desktop/Java学习笔记/牛客网学习/牛客-副本.md");
        long end = System.currentTimeMillis();
        System.out.println(end - start);


    }


    // 字节拷贝使用缓冲流
    public static void copyFile(String srcFilePath, String destFilePath) {
        try (
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFilePath));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFilePath));

                ) {
            byte[] bytes = new byte[128];
            int len =0; // 实际读取字节数
            while ((len = bis.read(bytes, 0, 128)) > 0) {
                bos.write(bytes, 0, len);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 字符拷贝使用缓冲流与上述方法大同小异

}
